package com.atguigu.tingshu.search.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/***
 * 搜索微服务使用的线程池
 */
@Configuration
public class SearchTreadPoolConfiguration {

    /**
     * 自定义线程池
     * @return
     */
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        // 初始化 + 设置
        ThreadPoolExecutor threadPoolExecutor =
                new ThreadPoolExecutor(16, // 核心线程数-
                        32, // 最大线程数
                        10, // 闲置时间
                        TimeUnit.SECONDS, // 闲置时间单位
                        new ArrayBlockingQueue<>(10000), // 阻塞队列
                        Executors.defaultThreadFactory(),  // 线程工厂对象
                        new ThreadPoolExecutor.AbortPolicy());  // 拒绝策略
        // 返回
        return threadPoolExecutor;
    }
}


